package com.humanresource.action.clerksalary;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.humanresource.constant.Constant;
import com.humanresource.domain.Result;
import com.humanresource.domain.po.clerkrecord.Clerkinstpos;
import com.humanresource.domain.po.clerkrecord.Inst;
import com.humanresource.domain.po.clerksalary.Salarydistribution;
import com.humanresource.domain.po.clerksalary.Salarydistributiondetail;
import com.humanresource.domain.po.clerksalary.Salarystandard;
import com.humanresource.domain.vo.clerksalary.SalaryDistributionDetailVO;
import com.humanresource.domain.vo.clerksalary.SalaryStandardBaseVO;
import com.humanresource.domain.vo.clerksalary.SalarydistributionVO;
import com.humanresource.service.clerkrecord.ClerkBaseInfoService;
import com.humanresource.service.clerkrecord.InstService;
import com.humanresource.service.clerksalary.SalarystandardService;
import com.humanresource.utils.DateUtil;
import com.humanresource.utils.RandomUtils;
import com.humanresource.utils.ResultUtil;

@Controller
@RequestMapping("/salary")
public class SalaryController {

	@Autowired
	private SalarystandardService salarystandardService;

	@Autowired
	private ClerkBaseInfoService clerkBaseInfoService;

	@Autowired
	private InstService instService;

	/**
	 * 1.3.1	薪酬标准管理
	 * 查询待登记的薪酬标准
	 * @return
	 */
	@RequestMapping(value = "/no/book", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result salaryListnobook() {
		List<SalaryStandardBaseVO> salaryStandardBaseVOs = new ArrayList<SalaryStandardBaseVO>();

		/**
		 * 获得当前未登记的薪酬标准
		 */
		List<Salarystandard> salarystandards = this.salarystandardService
				.findbyAuditstate(Constant.SALARYNOBOOK);
		// 不存在未登记的薪酬标准
		if (salarystandards.size() == 0) {
			return ResultUtil.success();
		}
		// 存在未登记的薪酬标准
		for (Salarystandard salarystandard : salarystandards) {
			SalaryStandardBaseVO salaryStandardBaseVO = new SalaryStandardBaseVO();
			BeanUtils.copyProperties(salarystandard, salaryStandardBaseVO);
			// 设置制定人名称
			salaryStandardBaseVO.setSettersname(this.clerkBaseInfoService
					.findById(salarystandard.getSettersid()).getClerkname());
			// 计算薪酬总额
			Float salarysummoney = salarystandard.getBasicsalary()
					+ salarystandard.getCommallowance()
					+ salarystandard.getTrafficallowance()
					+ salarystandard.getLunchallowance()
					- salarystandard.getEndowmentins()
					- salarystandard.getMedicalins()
					- salarystandard.getUneloymentins()
					- salarystandard.getHousingfund();
			// 设定薪酬总额
			salaryStandardBaseVO.setSalarysummoney(salarysummoney);

			salaryStandardBaseVOs.add(salaryStandardBaseVO);
		}
		return ResultUtil.success(salaryStandardBaseVOs);
	}

	/**
	 * 薪酬标准更新完后进行提交
	 * 养老保险 = 基本工资 * 8%
	 * 医疗保险 = 基本工资 * 2% + 3元
	 * 失业保险 = 基本工资 * 0.5%
	 * 住房公积金 = 基本工资 * 8%
	 * @param salaryStandardBaseVO
	 * @return
	 */
	@RequestMapping(value = "/update/standard", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result bookedupdate(
			@RequestBody SalaryStandardBaseVO salaryStandardBaseVO) {
		Salarystandard salarystandard = new Salarystandard();

		// 获得基本工资
		Float basicsalary = salaryStandardBaseVO.getBasicsalary();

		// 计算所有保险
		Float endowmentins = (float) (basicsalary * 0.08);// 养老保险
		Float medicalins = (float) (basicsalary * 0.02 + 3);// 医疗保险
		Float uneloymentins = (float) (basicsalary * 0.005);// 失业保险
		Float housingfund = (float) (basicsalary * 0.08);// 住房公积金

		BeanUtils.copyProperties(salaryStandardBaseVO, salarystandard);
		salarystandard.setEndowmentins(endowmentins); // 设置养老保险
		salarystandard.setMedicalins(medicalins); // 设置医疗保险
		salarystandard.setUneloymentins(uneloymentins); // 设置失业保险
		salarystandard.setHousingfund(housingfund); // 设置住房公积金

		// 设置登记人的员工编号bookerid
		salarystandard.setBookerid(this.clerkBaseInfoService.findByName(
				salaryStandardBaseVO.getBookername()).getClerkid());

		// 设置状态为待复核
		salarystandard.setAuditstate(Constant.SALARYNOCHECK);

		// 设置登记时间
		salarystandard.setBooktime(DateUtil.formatDateByFormat(new Date(),
				DateUtil.DATETIME_FORMAT));

		this.salarystandardService.update(salarystandard);
		return ResultUtil.success();
	}

	/**
	 * 列出所有待复核的薪酬标准
	 * @return
	 */
	@RequestMapping(value = "/no/check", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result salaryListnocheck() {
		List<SalaryStandardBaseVO> salaryStandardBaseVOs = new ArrayList<SalaryStandardBaseVO>();

		/**
		 * 获得当前待复核的薪酬标准
		 */
		List<Salarystandard> salarystandards = this.salarystandardService
				.findbyAuditstate(Constant.SALARYNOCHECK);
		// 不存在待复核的薪酬标准
		if (salarystandards.size() == 0) {
			return ResultUtil.success();
		}
		// 存在待复核的薪酬标准
		for (Salarystandard salarystandard : salarystandards) {
			SalaryStandardBaseVO salaryStandardBaseVO = new SalaryStandardBaseVO();
			BeanUtils.copyProperties(salarystandard, salaryStandardBaseVO);
			// 设置制定人名称
			salaryStandardBaseVO.setSettersname(this.clerkBaseInfoService
					.findById(salarystandard.getSettersid()).getClerkname());

			// 设置登记人名称
			salaryStandardBaseVO.setBookername(this.clerkBaseInfoService
					.findById(salarystandard.getBookerid()).getClerkname());

			// 计算薪酬总额
			Float salarysummoney = salarystandard.getBasicsalary()
					+ salarystandard.getCommallowance()
					+ salarystandard.getTrafficallowance()
					+ salarystandard.getLunchallowance()
					- salarystandard.getEndowmentins()
					- salarystandard.getMedicalins()
					- salarystandard.getUneloymentins()
					- salarystandard.getHousingfund();
			// 设定薪酬总额
			salaryStandardBaseVO.setSalarysummoney(salarysummoney);

			salaryStandardBaseVOs.add(salaryStandardBaseVO);
		}
		return ResultUtil.success(salaryStandardBaseVOs);
	}

	/**
	 * 薪酬标准复核或变更提交后进行更新操作
	 * * 养老保险 = 基本工资 * 8%
	 * * 医疗保险 = 基本工资 * 2% + 3元
	 * * 失业保险 = 基本工资 * 0.5%
	 * * 住房公积金 = 基本工资 * 8%
	 * @param salaryStandardBaseVO
	 * @return
	 */
	@RequestMapping(value = "/update/check", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result checkedupdate(
			@RequestBody SalaryStandardBaseVO salaryStandardBaseVO) {

		Salarystandard salarystandard = new Salarystandard();

		// 获得基本工资
		Float basicsalary = salaryStandardBaseVO.getBasicsalary();

		// 计算所有保险
		Float endowmentins = (float) (basicsalary * 0.08);// 养老保险
		Float medicalins = (float) (basicsalary * 0.02 + 3);// 医疗保险
		Float uneloymentins = (float) (basicsalary * 0.005);// 失业保险
		Float housingfund = (float) (basicsalary * 0.08);// 住房公积金

		BeanUtils.copyProperties(salaryStandardBaseVO, salarystandard);
		salarystandard.setEndowmentins(endowmentins); // 设置养老保险
		salarystandard.setMedicalins(medicalins); // 设置医疗保险
		salarystandard.setUneloymentins(uneloymentins); // 设置失业保险
		salarystandard.setHousingfund(housingfund); // 设置住房公积金

		// 如果是变更薪酬标准
		if (salaryStandardBaseVO.getChangepersonname() != null) {
			// 设置变更人职工编号
			salarystandard.setChangepersonid(this.clerkBaseInfoService
					.findByName(salaryStandardBaseVO.getChangepersonname())
					.getClerkid());
			salarystandard.setChangetime(DateUtil.formatDateByFormat(
					new Date(), DateUtil.DATETIME_FORMAT));
		} else {// 如果是复核薪酬标准，执行如下操作
			// 设置复核人的员工编号checkerid
			salarystandard.setCheckerid(this.clerkBaseInfoService.findByName(
					salaryStandardBaseVO.getCheckername()).getClerkid());
			salarystandard.setChecktime(DateUtil.formatDateByFormat(new Date(),
					DateUtil.DATETIME_FORMAT));
		}

		// 设置状态，如果是变更，则设置其状态为”待复核“，如果是复核，则设置其状态为”执行“
		salarystandard
				.setAuditstate(salaryStandardBaseVO.getChangepersonname() == null ? Constant.EXECUTE
						: Constant.SALARYNOCHECK);

		this.salarystandardService.update(salarystandard);
		return ResultUtil.success();
	}

	/**
	 * 薪酬标准查询
	 * * 薪酬标准编号、关键字和登记时间
	 * * 关键字查询条件在薪酬标准名称、制定人、变更人和复核人字段进行匹配
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/like/query", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result findquery(HttpServletRequest request) {
		String salarystandardid = request.getParameter("salarystandardid");
		String keyword = request.getParameter("keyword");
		String starttime = request.getParameter("starttime");
		String endtime = request.getParameter("endtime");
		List<Salarystandard> salarystandards = this.salarystandardService
				.findlikequery(salarystandardid, keyword, starttime, endtime);

		if (salarystandards.size() == 0) {
			return ResultUtil.success();
		}
		List<SalaryStandardBaseVO> salaryStandardBaseVOs = new ArrayList<SalaryStandardBaseVO>();
		for (Salarystandard salarystandard : salarystandards) {
			SalaryStandardBaseVO salaryStandardBaseVO = new SalaryStandardBaseVO();
			BeanUtils.copyProperties(salarystandard, salaryStandardBaseVO);
			// 设置制定人名称
			salaryStandardBaseVO.setSettersname(this.clerkBaseInfoService
					.findById(salarystandard.getSettersid()).getClerkname());

			// 设置登记人名称
			if (salarystandard.getBookerid() != null) {
				salaryStandardBaseVO.setBookername(this.clerkBaseInfoService
						.findById(salarystandard.getBookerid()).getClerkname());
			}

			// 设置复核人名称
			if (salarystandard.getCheckerid() != null) {
				salaryStandardBaseVO
						.setBookername(this.clerkBaseInfoService.findById(
								salarystandard.getCheckerid()).getClerkname());
			}
			// 设置变更人名称
			if (salarystandard.getChangepersonid() != null) {
				salaryStandardBaseVO.setBookername(this.clerkBaseInfoService
						.findById(salarystandard.getChangepersonid())
						.getClerkname());
			}
			// 计算薪酬总额
			Float salarysummoney = salarystandard.getBasicsalary()
					+ salarystandard.getCommallowance()
					+ salarystandard.getTrafficallowance()
					+ salarystandard.getLunchallowance()
					- salarystandard.getEndowmentins()
					- salarystandard.getMedicalins()
					- salarystandard.getUneloymentins()
					- salarystandard.getHousingfund();
			// 设定薪酬总额
			salaryStandardBaseVO.setSalarysummoney(salarysummoney);

			salaryStandardBaseVOs.add(salaryStandardBaseVO);
		}
		return ResultUtil.success(salaryStandardBaseVOs);
	}

	/**待登记薪酬发放列表
	 * 按III级机构列出需要进行发放登记的薪酬发放单
	 * 1.3.2	薪酬发放管理
	 * @return
	 */
	@RequestMapping(value = "/distribution/query/no/book", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result querydistribution() {

		/**
		 * 获得所有的薪酬待登记发放单
		 */
		List<Salarydistribution> salarydistributions = this.salarystandardService
				.findAllSalarystandardNoBook();

		if (salarydistributions.size() == 0) {
			return ResultUtil.success();
		}

		/**
		 * 存储待发放的薪酬发放单
		 */
		List<SalarydistributionVO> salarydistributionVOs = new ArrayList<SalarydistributionVO>();

		for (Salarydistribution salarydistribution : salarydistributions) {
			SalarydistributionVO salarydistributionVO = new SalarydistributionVO();
			BeanUtils.copyProperties(salarydistribution, salarydistributionVO);
			/**
			 *  获得三级机构
			 */
			Inst thirdinst = this.instService.findByName(salarydistribution
					.getInstname());
			// 设置三级机构名
			salarydistributionVO.setThirdinstname(thirdinst.getInstname());
			/**
			 * 获得二级机构
			 */
			Inst secondinst = this.instService.findPById(thirdinst.getInstid());
			// 设置二级机构名
			salarydistributionVO.setSecondinstname(secondinst.getInstname());
			/**
			 * 获得一级机构
			 */
			Inst firstinst = this.instService.findPById(secondinst.getInstid());
			// 设置一级机构名
			salarydistributionVO.setFirstinstname(firstinst.getInstname());
			/**
			 * 封装薪酬发放单
			 */
			salarydistributionVOs.add(salarydistributionVO);
		}
		return ResultUtil.success(salarydistributionVOs);
	}

	/**废弃
	 * 按III级机构列出需要进行发放登记的薪酬发放单
	 * 1.3.2	薪酬发放管理
	 * @return
	 */
	@RequestMapping(value = "/distribution/query/feiqi", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	@Deprecated
	public Result query() {
		/**
		 * 存储待发放的薪酬发放单
		 */
		List<SalarydistributionVO> salarydistributionVOs = new ArrayList<SalarydistributionVO>();

		/**
		 * 查询所有的机构
		 */
		Map<String, List<Inst>> instmap = instService.instList();

		/**
		 * 获得三级机构
		 */
		List<Inst> thirdInstList = instmap.get("三级机构");

		for (Inst inst : thirdInstList) {
			/**
			 * 根据机构获得该机构下的员工以及他们的职位
			 */
			List<Clerkinstpos> clerkinstposList = this.clerkBaseInfoService
					.findByInstId(inst.getInstid());

			// 如果该机构下暂没有员工则不用封装
			if (clerkinstposList.size() == 0) {
				continue;
			}

			/**
			 *  用于存储每个机构的薪酬待发放记录
			 */
			SalarydistributionVO salarydistributionVO = new SalarydistributionVO();

			/**
			 * 获得所有二级机构
			 */
			List<Inst> secondInstList = instmap.get("二级机构");

			/**
			 * 获得所有一级机构
			 */
			List<Inst> firstInstList = instmap.get("一级机构");

			// 封装三级机构名
			salarydistributionVO.setThirdinstname(inst.getInstname());

			// 封装二级机构名
			Inst secondinst = null;
			for (Inst inst2 : secondInstList) {
				if (inst2.getInstid().equals(inst.getInstpid())) {
					secondinst = inst2;
					salarydistributionVO.setSecondinstname(secondinst
							.getInstname());
					break;
				}
			}

			// 封装一级机构名
			for (Inst inst1 : firstInstList) {
				if (inst1.getInstid().equals(secondinst.getInstpid())) {
					salarydistributionVO.setFirstinstname(inst1.getInstname());
					break;
				}
			}

			// 封装该三级机构下的员工人数
			salarydistributionVO.setPersonnum(clerkinstposList.size());

			/**
			 * 获得该机构下的所有员工加起来的薪酬基本总额
			 */
			Float basicSalaryMoneySum = this.salarystandardService
					.getBasicSalaryMoneySum(clerkinstposList);

			// 封装基本薪酬总额
			salarydistributionVO.setBasicsalarysum(basicSalaryMoneySum);

			salarydistributionVOs.add(salarydistributionVO);
		}
		if (salarydistributionVOs.size() == 0) {
			return ResultUtil.success();
		}
		return ResultUtil.success(salarydistributionVOs);
	}

	/**
	 * 查询待登记或待复核的薪酬发放单详情
	 * @param instname
	 * @param auditstate 待登记或待复核
	 * @return
	 */
	@RequestMapping(value = "/distribution/query/no/book/{instname}/{auditstate}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result salaryDistributionDetailVOs(
			@PathVariable(value = "instname") String instname,
			@PathVariable(value = "auditstate") String auditstate) {
		List<SalaryDistributionDetailVO> salaryDistributionDetailVOs = new ArrayList<SalaryDistributionDetailVO>();
		/**
		 * 根据机构名获取所有在该这三级机构下的薪酬发放详情状态
		 */
		List<Salarydistributiondetail> salarydistributiondetails = this.salarystandardService
				.findByInstname(instname, auditstate);

		for (Salarydistributiondetail salarydistributiondetail : salarydistributiondetails) {
			SalaryDistributionDetailVO salaryDistributionDetailVO = new SalaryDistributionDetailVO();
			BeanUtils.copyProperties(salarydistributiondetail,
					salaryDistributionDetailVO);
			/**
			 * 设置员工姓名
			 */
			salaryDistributionDetailVO.setClerkname(this.clerkBaseInfoService
					.findById(salarydistributiondetail.getClerkid())
					.getClerkname());
			salaryDistributionDetailVOs.add(salaryDistributionDetailVO);
		}
		return ResultUtil.success(salaryDistributionDetailVOs, ""
				+ salarydistributiondetails.size());
	}

	/**
	 * 根据三级机构名查询该机构下的每个人的详细薪酬待发放登记记录,即返回薪酬发放登记明细
	 * 1.3.2	薪酬发放管理
	 * @return
	 */
	@Deprecated
	@RequestMapping(value = "/distribution/{instname}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result bookSalarydistribution(
			@PathVariable(value = "instname") String instname) {
		/**
		 * 根据三级机构名获得机构
		 */
		Inst inst = this.instService.findByName(instname);

		/**
		 * 根据三级机构编号找出该机构下的每个员工及每个员工的职位信息
		 */
		List<Clerkinstpos> clerkinstpos = this.clerkBaseInfoService
				.findByInstId(inst.getInstid());

		/**
		 * 根据clerkinstpos获取List<SalaryDistributionDetailVO>,即每个员工的详细薪酬单
		 */
		List<SalaryDistributionDetailVO> salaryDistributionDetailVOs = this.salarystandardService
				.getSalaryDistributionDetailVOListByClerkintpos(clerkinstpos);

		return ResultUtil.success(salaryDistributionDetailVOs);
	}

	/**
	 * 更新操作
	 * * 用于登记，复核，变更
	 * @param salaryDistributionDetailVO
	 * @return
	 */
	@RequestMapping(value = "/distribution/submit/update", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result update(
			@RequestBody SalaryDistributionDetailVO salaryDistributionDetailVO) {
		Salarydistributiondetail salaryDistributionDetail = new Salarydistributiondetail();
		BeanUtils.copyProperties(salaryDistributionDetailVO,
				salaryDistributionDetail);

		/**
		 * 根据clerkname获取clerkid
		 */
		salaryDistributionDetail.setClerkid(this.clerkBaseInfoService
				.findByName(salaryDistributionDetailVO.getClerkname())
				.getClerkid());

		/**
		 * 更新薪酬发放单
		 */
		this.salarystandardService
				.updateSalaryDistribution(salaryDistributionDetail);

		/**
		 * 更新薪酬详细发放表
		 */
		this.salarystandardService
				.updateSalaryDistributionDetail(salaryDistributionDetail);

		return ResultUtil.success();

	}

	@Deprecated
	@RequestMapping(value = "/create/sd", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result createSalaryDistribution(
			@RequestBody SalarydistributionVO salarydistributionVO) {
		Salarydistribution salarydistribution = new Salarydistribution();

		BeanUtils.copyProperties(salarydistributionVO, salarydistribution);

		/**
		 * 生成薪酬发放单编号
		 */
		String SalaryDistributionId = RandomUtils.generateString(16);

		// 设置薪酬发放单编号
		salarydistribution.setSalarydistributionid(SalaryDistributionId);

		// 设置登记状态
		salarydistribution.setIsbook("登记");

		// 设置机构名
		salarydistribution.setInstname(salarydistributionVO.getThirdinstname());

		// 设置为待复核
		salarydistribution.setIscheck(Constant.SALARYNOCHECK);

		this.salarystandardService.createSalaryDistribution(salarydistribution);

		return ResultUtil.success();
	}

	/**
	 * 查询未复核的薪酬发放表
	 * @return
	 */
	@RequestMapping(value = "/distribution/nocheck", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result SalaryDistributionNoCheck() {

		List<SalarydistributionVO> salarydistributionVOs = new ArrayList<SalarydistributionVO>();
		/**
		 * 得到待复核的薪酬发放表
		 */
		List<Salarydistribution> salarydistributions = this.salarystandardService
				.findSalaryDistributionNoCheck();

		if (salarydistributions.size() == 0) {
			return ResultUtil.success();
		}
		for (Salarydistribution salarydistribution : salarydistributions) {
			SalarydistributionVO salarydistributionVO = new SalarydistributionVO();
			BeanUtils.copyProperties(salarydistribution, salarydistributionVO);
			/**
			 * 封装I级，II级，III级机构名
			 */
			// 封装III级机构名
			salarydistributionVO.setThirdinstname(salarydistribution
					.getInstname());
			Inst inst3 = this.instService.findByName(salarydistribution
					.getInstname());

			// 封装II级机构名
			Inst inst2 = this.instService.findPById(inst3.getInstid());
			salarydistributionVO.setSecondinstname(inst2.getInstname());

			// 封装I级机构名
			Inst inst1 = this.instService.findPById(inst2.getInstid());
			salarydistributionVO.setFirstinstname(inst1.getInstname());

			salarydistributionVOs.add(salarydistributionVO);
		}
		return ResultUtil.success(salarydistributionVOs);
	}

	/**待登记薪酬发放列表
	 * 按III级机构列出需要进行发放登记的薪酬发放单
	 * 1.3.2	薪酬发放管理
	 * @return
	 */
	@RequestMapping(value = "/distribution/query/no/check", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Result querydistributionwithnocheck() {

		/**
		 * 获得所有的薪酬待登记发放单
		 */
		List<Salarydistribution> salarydistributions = this.salarystandardService
				.findAllSalarystandardNoCheck();

		if (salarydistributions.size() == 0) {
			return ResultUtil.success();
		}

		/**
		 * 存储待发放的薪酬发放单
		 */
		List<SalarydistributionVO> salarydistributionVOs = new ArrayList<SalarydistributionVO>();

		for (Salarydistribution salarydistribution : salarydistributions) {
			SalarydistributionVO salarydistributionVO = new SalarydistributionVO();
			BeanUtils.copyProperties(salarydistribution, salarydistributionVO);
			/**
			 *  获得三级机构
			 */
			Inst thirdinst = this.instService.findByName(salarydistribution
					.getInstname());
			// 设置三级机构名
			salarydistributionVO.setThirdinstname(thirdinst.getInstname());
			/**
			 * 获得二级机构
			 */
			Inst secondinst = this.instService.findPById(thirdinst.getInstid());
			// 设置二级机构名
			salarydistributionVO.setSecondinstname(secondinst.getInstname());
			/**
			 * 获得一级机构
			 */
			Inst firstinst = this.instService.findPById(secondinst.getInstid());
			// 设置一级机构名
			salarydistributionVO.setFirstinstname(firstinst.getInstname());
			/**
			 * 封装薪酬发放单
			 */
			salarydistributionVOs.add(salarydistributionVO);
		}
		return ResultUtil.success(salarydistributionVOs);
	}

}
